//
//  YXCustomPanel.m
//  YXClient
//
//  Created by 张明磊 on 14-8-12.
//  Copyright (c) 2014年 张明磊. All rights reserved.
//

#import "YXCustomPanel.h"
#import "MYBlurIntroductionView.h"
#import "KWLLoginViewController.h"
#import "YXBeginViewController.h"

@interface YXCustomPanel ()

@property (weak, nonatomic) UIImageView *imageView_one;
@property (weak, nonatomic) UIImageView *imageView_two;

@property (assign, nonatomic) NSInteger int_tag;

@property (weak, nonatomic) UIView *view_login;

@end

@implementation YXCustomPanel

- (id)initWithFrame:(CGRect)frame andTag:(NSInteger )tag
{
    _int_tag = tag;
    self = [super initWithFrame:frame];
    if (self) {
        switch (tag) {
            case 0:{
                [self installBeginView_one];
            }break;
            case 1:{
                [self installBeginView_two];
            }break;
            case 2:{
                [self installBeginView_three];
            }break;
            case 3:{
                [self installBeginView_four];
            }break;
            default:
                break;
        }
    }
    return self;
}

- (void)panelDidAppear{
    switch (_int_tag) {
        case 0:{
            
        }break;
        case 1:{
            
        }break;
        case 2:{
            
        }break;
        case 3:{
            UIButton *button_begin = [UIButton buttonWithType:UIButtonTypeCustom];
            if(IOS6_VERSION){
                 button_begin.frame = CGRectMake(30, self.frame.size.height - 100 + 20, 260, 40);
            }
            else{
                button_begin.frame = CGRectMake(30, self.frame.size.height - 120 + 25, 260, 40);
            }
            button_begin.alpha = 0.0;
            button_begin.backgroundColor = [UIColor clearColor];
            [button_begin setImage:[UIImage imageFileName:@"button_begin.png"] forState:UIControlStateNormal];
            [button_begin addTarget:self action:@selector(didClickButton_begin:)forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:button_begin];
            
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            [UIView setAnimationDuration:0.4f];
            [UIView setAnimationRepeatCount:1];
            [UIView setAnimationBeginsFromCurrentState:YES];
            button_begin.alpha = 1.0;
            [UIView commitAnimations];
        }break;
        default:
            break;
    }
}

- (void)panelDidDisappear{
    switch (_int_tag) {
        case 0:{
            
        }break;
        case 1:{
            
        }break;
        case 2:{
        
        }break;
        case 3:{
            
        }break;
        default:
            break;
    }
}

- (void)didClickButton_begin:(UIButton *)button{
    KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:5];
    YXBeginViewController *begin = (YXBeginViewController *)[self reciveSuperViewControllerWithView:self];
    [begin.navigationController pushViewController:login animated:NO];
}

- (UIViewController *)reciveSuperViewControllerWithView:(UIView *)view{
    for (UIView *next = [view superview]; next; next = next.superview)
    {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]){
            return (UIViewController *)nextResponder;
        }
    }
    return nil;
}

- (void)installBeginView_one{
    UIImageView *imageView_one = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, [UIUtils windowHeight])];
    [imageView_one setContentMode:UIViewContentModeScaleAspectFill];
    if(iPhone5){
        imageView_one.image = [UIImage imageFileName:@"begin_one_h.png"];
    }
    else{
        imageView_one.image = [UIImage imageFileName:@"begin_one.png"];
    }
    [self addSubview:imageView_one];
}

- (void)installBeginView_two{
    UIImageView *imageView_two = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, [UIUtils windowHeight])];
    [imageView_two setContentMode:UIViewContentModeScaleAspectFill];
    if(iPhone5){
        imageView_two.image = [UIImage imageFileName:@"begin_two_h.png"];
    }
    else{
        imageView_two.image = [UIImage imageFileName:@"begin_two.png"];
    }
    [self addSubview:imageView_two];
}

- (void)installBeginView_three{
    UIImageView *imageView_three = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, [UIUtils windowHeight])];
    [imageView_three setContentMode:UIViewContentModeScaleAspectFill];
    if(iPhone5){
        imageView_three.image = [UIImage imageFileName:@"begin_three_h.png"];
    }
    else{
        imageView_three.image = [UIImage imageFileName:@"begin_three.png"];
    }
    [self addSubview:imageView_three];
}

- (void)installBeginView_four{
    UIImageView *imageView_four = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, [UIUtils windowHeight])];
    [imageView_four setContentMode:UIViewContentModeScaleAspectFill];
    if(iPhone5){
        imageView_four.image = [UIImage imageFileName:@"begin_four_h.png"];
    }
    else{
        imageView_four.image = [UIImage imageFileName:@"begin_four.png"];
    }
    [self addSubview:imageView_four];
}

@end
